define(["jquery", "easy-admin"], function ($, ea) {


    var querys = {}

    querys.gpu_id = ea.getQueryVariable('gpu_id');

    var querys_str = $.param(querys);

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'app.gpu_price/index?search_type=' + ea.getQueryVariable('search_type', 'all'),
        add_url: 'app.gpu_price/add?' + querys_str,
        edit_url: 'app.gpu_price/edit',
        delete_url: 'app.gpu_price/delete',
        export_url: 'app.gpu_price/export',
        modify_url: 'app.gpu_price/modify',
    };


    function bindTitleTplInput() {
        $('.title-tpl-input').click(function () {
            $('input[name="title"]').val($(this).text())
        })
    }

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'add', 'export'],
                cols: [[
                    { type: 'checkbox' },
                    { type: 'numbers', title: '排序', sort: false },
                    { field: 'id', title: 'id' },
                    { field: 'type', search: 'select', selectList: ea.getDataBrage('select_list_type'), title: '报价类型' },
                    { field: 'appGpu.title', title: '显卡名称', minWidth: 200 },
                    { field: 'appGpu.cuda_count', title: 'CUDA核心数', search: 'number_limit' },
                    { field: 'appGpu.memory', title: '标准显存（G）', search: 'number_limit' },
                    { field: 'price', title: '报价', search: 'number_limit' },
                    { field: 'cost_price', title: 'CUDA核心单价', search: false },
                    { field: 'title', title: '报价名称' },
                    { field: 'link', title: '报价链接' },
                    { field: 'desc', title: '配置说明' },
                    { field: 'desc_image', title: '截图', templet: ea.table.image },
                    { field: 'status', search: 'select', selectList: ea.getDataBrage('select_list_status'), title: '比价状态', templet: ea.table.switch },
                    { field: 'gpu_id', title: 'GPU', trueHide: true, search: true, defaultSearchValue: querys.gpu_id, searchOp: '=' },
                    { field: 'appGpu.boost_clock', title: '加速频率 （GHz）' },
                    { field: 'appGpu.base_clock', title: '基础频率 （GHz）' },
                    {
                        width: 250, title: '操作', templet: ea.table.tool, fixed: 'right', operat: [
                            [
                                {
                                    text: '详情',
                                    url: '/price/',
                                    method: 'open',
                                    class: 'layui-btn layui-btn-success layui-btn-xs',
                                    field: function (data, option) {
                                        return option.url + '/' + data.id
                                    }
                                },
                                {
                                    class: 'layui-btn layui-btn-success layui-btn-xs',
                                    method: 'open',
                                    field: 'id',
                                    icon: '',
                                    text: '编辑',
                                    title: '编辑信息',
                                    auth: 'edit',
                                    url: init.edit_url,
                                    extend: "",
                                    _if(data) {
                                        if (CONFIG.IS_SUPER_ADMIN) {
                                            return true;
                                        }
                                        if (data.user_id == ea.getDataBrage('session_admin.id')) {
                                            return true;
                                        }

                                        return false
                                    }
                                },
                                {
                                    class: 'layui-btn layui-btn-danger layui-btn-xs',
                                    method: 'get',
                                    field: 'id',
                                    icon: '',
                                    text: '删除',
                                    title: '确定删除？',
                                    auth: 'delete',
                                    url: init.delete_url,
                                    extend: "",
                                    _if(data) {
                                        if (CONFIG.IS_SUPER_ADMIN) {
                                            return true;
                                        }
                                        if (data.user_id == ea.getDataBrage('session_admin.id')) {
                                            return true;
                                        }

                                        return false
                                    }
                                }
                            ]
                        ]
                    },
                ]],
            });

            ea.listen();
        },
        add: function () {
            bindTitleTplInput()
            ea.listen();
        },
        edit: function () {
            bindTitleTplInput()
            ea.listen();
        },
    };
    return Controller;
});